package com.yhty.web.action;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yhty.model.PayMent;
import com.yhty.model.User;
import com.yhty.service.PayManager;

/**
 * 缴费action
 * @author RoySong
 * 2011-3-30-下午12:01:21
 */
@Controller
@RequestMapping("/pay")
public class PayAction {

	private PayManager payManager;

	@Resource(name="payManager")
	public void setPayManager(PayManager payManager) {
		this.payManager = payManager;
	}
	
	/**
	 * 缴纳费用
	 * @param payMent
	 * @param model
	 * @param session
	 * @return
	 */
	@RequestMapping(value="/deal",method=RequestMethod.POST)
	public @ResponseBody
	Map<String,Object> pay(PayMent payMent,Model model,HttpSession session){
		Map<String,Object> result = new HashMap<String,Object>();
		try{
			User user=(User)session.getAttribute("user");
			payMent.setUser(user);
			payManager.pay(payMent);
		}catch(Exception e){
			e.printStackTrace();
			result.put("success", false);
			return result;
		}
		result.put("success", true);
		return result;
	}
}
